package cn.edu.bupt.ch3_1.controller;

import cn.edu.bupt.ch3_1.service.AsyncTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class AsyncTestController {
    private AsyncTestService asyncTestService;

    @Autowired //此注解可省略
    public AsyncTestController(AsyncTestService asyncTestService) {
        this.asyncTestService = asyncTestService;
    }

    @GetMapping("/sync")
    public String sync() {
        asyncTestService.syncMethod();
        Date date = new Date();
        return date.toString();
    }

    @GetMapping("/async")
    public String async() {
        asyncTestService.asyncMethod();
        Date date = new Date();
        return date.toString();
    }
}
